package org.stvd.service.admin.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.stvd.core.dto.QueryResult;
import org.stvd.entities.admin.Params;
import org.stvd.repository.admin.ParamsDao;
import org.stvd.service.admin.ParamsService;
import org.stvd.service.base.impl.BaseServiceImpl;

@Service("paramsService")
public class ParamsServiceImpl extends BaseServiceImpl<Params> implements ParamsService {

    @Resource(name = "ParamsDao")
    private ParamsDao paramsDao;

    @Override
    public QueryResult<Params> getParamQueryResult(int start, int limit, String paramName, String guid) {
        return paramsDao.getParamQueryResult(start, limit, paramName, guid);
    }

    @Override
    public List<Params> findAll(String guid) {
        return paramsDao.findAll(guid);
    }

    @Override
    public Params getByParamName(String guid, String paramName) {
        List<Params> paramsList = findByParamName(guid, paramName);
        if(paramsList!=null && paramsList.size() > 0) {
            return paramsList.get(0);
        }
        return null;
    }
    
    @Override
    @Cacheable(value="adminCache",key="'ParamsService.findByParamName('+#guid+','+#paramName+')'")
    public List<Params> findByParamName(String guid, String paramName) {
        return paramsDao.findByParamName(guid, paramName);
    }
    
    @Override
    @Transactional
    @CacheEvict(value="adminCache",allEntries=true)
    public void delete(Object pk) {
        super.delete(Params.class, pk);
    }

    @Override
    @Transactional
    @CacheEvict(value="adminCache",allEntries=true)
    public void insert(Params entity) {
        super.insert(entity);
    }

    @Override
    @Transactional
    @CacheEvict(value="adminCache",allEntries=true)
    public void update(Params entity) {
        super.update(entity);
    }

}
